              C h a p t e r   S i x                                                                                                                                                                                                             B A S I C   P r o g r a m m i n g                                                                                                                                                                                                                      PgUp:  Previous Page       Alt PgUp:  Chapter Five                                                    PgDn:  Next Page           Alt PgDn:  The End                                                                        Esc:  Sound On/Off                                                                         o|                    Diskette Drive                o|                    Ŀ         \/       o|                     ͳĳ                          𰱱       o|                                                   o|                                                                o|                                                                                                            /\                                                                              ͻ                                                      Computer                                                 ͼ                              ͻ                                           ۺ    Keyboard                                                   ͼ                            ͻ    Keyboard  ͼo|                 |oo|                 |oo|                 |oo|                 |oo|                 |oo|                 |o             C o m p u t e r   P r o g r a m s                                                                                                   A program is a list of instructions that tells the computer what to do.  Programs control its keyboard, disk drives,    display, and printer.                                                                                                   Everything that the Personal Computer does must be          controlled by a program.                                                 C o m p u t e r   P r o g r a m s                                                                                          The instructions for a program are written in one of the many programming languages available for your computer.                                                           We'll use BASIC, the language which comes with the IBM   Personal Computer.                                        \/                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           The IBM Personal Computer DOS     (C)Copyright IBM Corp. 1981 - 1984                                  A>                                          P r a c t i c e   B A S I C                                                                                 This lesson uses Practice BASIC.  It's like disk BASIC, a version of BASIC supplied as a file on  your DOS diskette.                                                                                To save time, we've put the Practice DOS disketteinto drive A and started up DOS for you.                S t a r t i n g   B A S I C                                                                     Let's load the Practice BASIC language file from the Practice DOS diskette, into the    Personal Computer's internal memory.                                                              1.  Type:  BASIC                            2.  Press the Enter key.          The IBM Personal Computer BASIC   (C)Copyright IBM Corp. 1981 - 198424050 Bytes free                  Ok                                        W e l c o m e   T o   B A S I C                                                                                             Like DOS, BASIC has many commands.  DOS commands do    not work in BASIC and vice versa.                                                                             BASIC commands can be typed in upper or lower case.    The ten Function keys are used in BASIC to save typing.          L o a d   A   P r o g r a m                                                                                          Let's load the program file CLOCK from the "cartoon"diskette now in drive A.                                                                                        1.  Press the F3 Function key.                      2.  Type:   CLOCK"                                  3.  Press the Enter key.                              L i s t   T h e   P r o g r a m                                                                                  Now let's use the LIST command to display a copy of the CLOCK program on the screen.                                                                                1.  Press the F1 Function key.                      2.  Press the Enter key.                            3.  Study the CLOCK program.                             T r y   I t   O u t !                                                                                                      Notice that each line in the program has a number    and a BASIC command.  Let's RUN CLOCK in slow motion,one line at a time.                                                                                             1.  Keep your eye on the screen!                     2.  Press the F2 Function key.                        C h a n g e   T h e   P r o g r a m                                                                 Let's change Line 40 of the program so that the CLOCK can run continuously.                                                                              1.  Type:  40 GOTO 20                           2.  Press the Enter key.                        3.  LIST the modified program.                 T i c k ,   T i c k ,   T i c k !                                                                          Now RUN the modified version of CLOCK to see that it really does run continuously.                                                                           1.  Glue your eyes to the screen.                 2.  Press the F2 Function key.                    3.  Enjoy your new digital clock!                 S a v e   Y o u r   P r o g r a m                                                                  Let's SAVE a copy of the modified program as a program file on the "cartoon" diskette.                                                               1.  Press the F4 Function key.                 2.  Type:   CLOCK2"                            3.  Press the Enter key.                           P r i n t   I t   O u t                                                                                          If you have an IBM Graphics Printer, you can use  the LLIST command to print out CLOCK2.  Make sure the printer is ONLINE.                                                                                       1.  Type:   LLIST                                 2.  Press the Enter key.                 You don't need to write computer programs to use your     Personal Computer, but it will be rewarding if you take   the time to learn.                                                                                                  BASIC has more than 150 unique commands.  If you'd like   to learn more about them or try writing your own programs,open the IBM BASIC Manual and dig in!  Good luck.                       1 0   C L S                                                                               This command Clears the Screen.  Watch!         2 0   L O C A T E   6 ,   1 4                                                                           This one puts the cursor on line six, 14 spaces from the left edge of the screen.                         3 0   P R I N T   T I M E $                                                                              This displays the current time, accurate to the second.  (You set the clock earlier when you    started using DOS, remember?)                                4 0   E N D                                                                             This is the end of the CLOCK program.                                       Press PgDn to go on.                            P r o g r a m   L o a d e d                                                                                             A copy of the program file CLOCK has been loaded fromthe "cartoon" diskette into the Personal Computer's  internal memory.                                                   W r o n g   F i l e                                                                                 The only file you may load in Practice BASIC is named CLOCK.                                                                                1.  Press the F3 Function key.               2.  Type:   CLOCK"                           3.  Press the Enter key.                          M i s s i n g   Q u o t e s                                                                                       You must put quotes before and after the file name as in:    LOAD "CLOCK".                                                                                    1.  Press the F3 Function key..                    2.  Type:  CLOCK"                                  3.  Press the Enter key.                                 P r o g r a m   S a v e d                                                                                                      Good.  Your program is now saved on the "cartoon"      diskette as a program file named CLOCK2.BAS.  (DOS     automatically adds the .BAS extension to BASIC program files.)  If you'd like, LIST or RUN the program again.               W r o n g   F i l e                                                                                                Practice BASIC will only allow you to save CLOCK2.Try the SAVE command again:                                                                              1.  Press the F4 Function key.                    2.  Type:   CLOCK2"                               3.  Press the Enter key.                                  B a d   C o m m a n d                                                                                             Practice BASIC doesn't know the command you typed.Use one of these commands:                                                                               LOAD   LIST   RUN   SAVE   CONT   LLIST                                                        Please press PgUp and try again.                                  N o t   Y e t                                                                                           Please don't try to change line 40 right now.You will have plenty of time later.                                                       Press PgUp and follow the instructions.                     T r y   A g a i n                                                                               Please type the change exactly like this:                                                             40 GOTO 20                              W r o n g   F i l e                                                                                                   The only file available in Practice BASIC is named CLOCK.  You can either type RUN "CLOCK" or just    press the F2 key.                                                                                     Press PgUp and try again.                                    M i s s i n g   Q u o t e s                                                                                             If you use a filename with RUN, it must be in quotes,as in RUN "CLOCK".  You can also RUN the program by  pressing the F2 key.                                                                                      Press PgUp and try again.                                      S t a r t i n g   B A S I C                                                                     At this point in the lesson, you should type the following to load Practice BASIC.                                                             1.  Type:   BASIC                            2.  Press the Enter key.                       M i s s i n g   Q u o t e s                                                                                       You must put quotes before and after the file name as in:     SAVE "CLOCK2".                                                                                  1.  Press the F4 Function key.                     2.  Type:  CLOCK2"                                 3.  Press the Enter key.                              T i c k ,   T i c k ,   T i c k !                                                                                      This program never ends.  You can stop it by pressing the Ctrl and Break keys so that both keys are down at the same time.  (Break is another name for the Scroll Lock key.)  Try Ctrl Break now.                                       H o l d   I t !                                                                                                   The message below means that the program was     stopped while it was on line 30.                                                                  Press the F5 Function key to CONTinue the programor press PgDn to go on.                          ClS                   Now is the  time for all    good men to      Now is the  time for all    good men to   come to the    time for all    good men to   come to the     aid of their   good men to   come to the     aid of their  country.       come to the     aid of their  country.                       aid of their  country.                         Now is the  country.                         Now is the  time for all                       Now is the   time for all goodmen to come to   the aid of their country.             Now is the   time for all goodmen to come to   the aid of their country.                          time for all goodmen to come to   the aid of their country.                              Now is the   men to come to   the aid of their country.                              Now is the   time for all goodthe aid of their country.                              Now is the   time for all goodmen to come to   country.                              Now is the   time for all goodmen to come to   the aid of their               W h a t ' s   N e x t                                                                                                     This completes the lesson.  Now, you can:                                                                 1.  Review the lesson.  Press Alt PgUp.                                                                   2.  If you need to:                                                                                           - Learn more about operating your system... Refer      to the Guide to Operations manual.                                                                      - Learn more about DOS... Read the DOS User's          Guide and/or refer to the DOS Reference manual.                                                         - Setup an application... Use the Application          Setup Guide.                                                                                            - Run an application... Use the Application Setup      Guide and your application manual.                                                                  3.  End the lesson.  Remove the lesson diskette and      turn the power OFF.                              If you need to: need to:ette in its      place.  Then press these three keys at once        to reset the computer:  Ctrl Alt Del          e the lesson disk-        ette and insert a new program diskette in its      place.  Then press these three keys at once        to reset the computer:  Ctrl Alt Del          n its      place.  Then press these three keys at once        to reset the computer:  Ctrl Alt Del                                                                                                            